﻿using Newtonsoft.Json.Linq;
using NLog;
using Persistence.Core;
using QueryDataLogic.Core;
using System;
using System.Data.SqlClient;

namespace PersistenceDataLogic.Core
{
    public class OperationSystemSetting
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        PersistenceData pd = new PersistenceData();
        QueryData qd = new QueryData();
        BasicInfo bi = new BasicInfo();

        /// <summary>
        /// 修改 强制点菜 配置
        /// </summary>
        /// <returns></returns>
        public JObject OptConstraintDishes(JObject joParam)
        {
            JObject joResult = new JObject();

            try
            {
                int id = (int)joParam["id"];
                string value = (string)joParam["value"];
                int resultLine = 0;
                SqlCommand comm = new SqlCommand();

                comm.CommandText = "UPDATE SystemSetting SET value = @value WHERE id = @id ";

                comm.Parameters.AddWithValue("@id", id);
                comm.Parameters.AddWithValue("@value", value);

                resultLine = pd.ExeSqlCode(comm, "MealManage");

                if (resultLine > 0)
                {
                    joResult["message"] = "强制点菜属性配置成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else
                {
                    joResult["message"] = "强制点菜属性配置失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                Console.Write(ex);
                joResult["data"] = 0;
                joResult["message"] = ex.Message + "\n" + ex.StackTrace;
                joResult["state"] = false;
            }

            return joResult;
        }
    }
}
